﻿using System;
using RayDen.Library.Core;
using RayDen.Library.Core.Primitives;

namespace RayDen.Library.Components.Surface
{
    public class BrdfToBtdf : SurfaceBsdf
    {

        private SurfaceBsdf brdf;
        public BrdfToBtdf(SurfaceBsdf brdf)
        {
            this.brdf = brdf;
        }

        public override void f(ref Vector wo, ref Vector wi, ref Normal N, ref RgbSpectrum in_fs, out RgbSpectrum fs)
        {
            var i_wi = new Vector(wi.x, wi.y, -wi.z);
            brdf.f(ref wo, ref i_wi, ref N, ref in_fs, out fs);
        }

        public override void Sample_f(ref Vector wo, ref Normal N, ref Normal shadeN, ref RgbSpectrum in_f, float u0, float u1, float u2,
            ref SurfaceTextureData surfaceData, out BsdfSampleData result)
        {
            base.Sample_f(ref wo, ref N, ref shadeN, ref in_f, u0, u1, u2, ref surfaceData, out result);
            result.Wi = new Vector(result.Wi.x, result.Wi.y, -result.Wi.z);
        }

        public override BrdfType Type
        {
            get { return BrdfType.Refractive| brdf.Type; }
        }

        public override bool IsDiffuse()
        {
            return brdf.IsDiffuse();
        }

        public override bool IsSpecular()
        {
            return brdf.IsSpecular();
        }
    }
}